package net.huashitong.scheduling.dao;

import java.util.List;

import com.sirdc.modules.core.filter.BaseFilter;
import com.sirdc.modules.utils.ObjectUtils;
import org.springframework.stereotype.Repository;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;

import net.huashitong.scheduling.entity.FinanceIncome;

@Repository
public class FinanceIncomeDao extends StringDao<FinanceIncome>{
	public List<FinanceIncome> queryList(){
		 GenericQuery query = createQuery("obj");
		 query.append(" order by cast(obj.sysId as int) ASC");
		 return query.listResult();
	}
    
	public FinanceIncome queryByName(String name,String year,String month){
		 GenericQuery query = createQuery("obj");
		 query.append(" and obj.name= :name").setParam("name", name);
		 query.append(" and obj.year= :year").setParam("year", year);
		 query.append(" and obj.month= :month").setParam("month", month);
		 return query.firstResult();
	}
	
	public List<FinanceIncome> queryListByDate(String year,String month){
		 GenericQuery query = createQuery("obj");
		 query.append(" and obj.year= :year").setParam("year", year);
		 query.append(" and obj.month= :month").setParam("month", month);
		 return query.listResult();
	}

	public String queryNewDate(){
		GenericQuery query = createQuery("obj");
		query.setOrder("sysId+0", BaseFilter.DESC);

		FinanceIncome object = query.firstResult();
		if(ObjectUtils.isBlank(object)){
			return "2020-03";
		}
		return object.getYear()+"-"+object.getMonth();
	}
	public List<FinanceIncome> queryListByParentId(String parentId){
		 GenericQuery query = createQuery("obj");
		 query.append(" and obj.parentId= :parentId").setParam("parentId", parentId);
		
		 return query.listResult();
	}
}
